package com.ys.web.mobao.model.po;

import com.ys.utils.base.j2se.StringHandler;
import com.ys.utils.mobao.Mobo360Config;
import com.ys.utils.spring.config.SystemError;
import com.ys.utils.spring.properties.Config;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * 钱包开户bean
 */
@Data
public class MobaoWithholdingCreate extends PayBase {
    public String currency="CNY";
    public String amount;
    public String arrivalAmount;
    public String notifyUrl= Mobo360Config._notifyUrl+"/onlinePay/transferDomestic/single/order/send";
    public String ys_otifyUrl= Mobo360Config._notifyUrl+"/ys/callBack/withdraw/notify";
    public String remark;
    public String cardToken;
    public String payPassword;
    // 是否需要审核
    public boolean wait = false;
    //是否免服务费
    public int noFee = 2;

    public void check(String uid){
        LocalDateTime time = LocalDateTime.now();
        int hour1 = StringHandler.getInt(Config.pp.get("wallet.withholding.hour.min"));
        int hour2 = StringHandler.getInt(Config.pp.get("wallet.withholding.hour.max"));
        if(!whiteList(uid)) {
            if (time.getHour() < hour1 || time.getHour() > hour2) {
                SystemError.wrapBs("400", String.format("每日提现时间为%s点到%s点", hour1, hour2));
            }
        }
        long compareMoney = StringHandler.getLong(StringHandler.parseMoney(amount));
        long min = StringHandler.getLong(Config.pp.get("wallet.withholding.money.min"));
        if (compareMoney < min) {
            SystemError.wrapBs("400", "提现金额不能小于" + StringHandler.moneyDesc(min) + "元");
        }
        long max = StringHandler.getLong(Config.pp.get("wallet.withholding.money.max"));
        if (compareMoney > max) {
            SystemError.wrapBs("400", "提现金额不能大于" + StringHandler.moneyDesc(max) + "元");
        }

        //风控规则
        if(compareMoney>StringHandler.getLong(Config.pp.get("wallet.withholding.wait.money"))){
            this.wait = true;
        }

        this.amount = String.valueOf(StringHandler.yuanToFen(this.amount));
    }
    public boolean whiteList(String uid){
        String str =Config.pp.get("wallet.user.white.list");
        if(StringHandler.isNotEmpty(str)){
            List<String> list = Arrays.asList(str.split(","));
            if(list.contains(uid)){
                return true;
            }
        }
        return false;
    }
    @Override
    public String getCurrency() {
        return currency;
    }

    @Override
    public void setCurrency(String currency) {
        this.currency = currency;
    }

    public String getAmount() {
        return amount;
    }

    public void setAmount(String amount) {
        this.amount = amount;
    }

    public String getArrivalAmount() {
        return arrivalAmount;
    }

    public void setArrivalAmount(String arrivalAmount) {
        this.arrivalAmount = arrivalAmount;
    }

    public String getNotifyUrl() {
        if(this.payChannel=="ys"){
            return ys_otifyUrl;
        }
        return notifyUrl;
    }

    public void setNotifyUrl(String notifyUrl) {
        if(this.payChannel=="ys"){
            this.notifyUrl = ys_otifyUrl;
        }else{
            this.notifyUrl = notifyUrl;
        }
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getCardToken() {
        return cardToken;
    }

    public void setCardToken(String cardToken) {
        this.cardToken = cardToken;
    }

    public String getPayPassword() {
        return payPassword;
    }

    public void setPayPassword(String payPassword) {
        this.payPassword = payPassword;
    }

    public boolean isWait() {
        return wait;
    }

    public void setWait(boolean wait) {
        this.wait = wait;
    }

    public int getNoFee() {
        return noFee;
    }

    public void setNoFee(int noFee) {
        this.noFee = noFee;
    }

}
